import req from './../../../fetch'; import { undocumentedResponse } from './../../../utils'; import { AllAPIResponses, CarbonError, NetworkType, ClaimType, } from './../../../index'; type Params = { networkType: NetworkType; }; type Payload = { appKey?: string; functionName: string; functionVersion: string; uniqueId: string; }; const post = async ( params: Params, body: Payload, headers?: Headers ): Promise> => { try { const resp = await req.post( `/api/claims/${params.networkType}`, JSON.stringify(body), headers ); const clone = resp.clone(); switch (resp.status) { case 201: return { data: (await resp.json()) as ClaimType, response: clone, }; case 400: case 401: case 403: case 404: case 500: return { error: (await resp.json()) as CarbonError, response: clone, }; default: return { error: new Error(undocumentedResponse(resp)), response: clone, }; } } catch (e) { return { error: e, response: undefined }; } }; export default post;